package com.xiao.provider.controller;

import com.xiao.provider.service.UserService;
import com.xiao.provider.vo.reqvo.UserReqVo;
import com.xiao.provider.vo.resvo.UserResVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @Description 对内部服务提供的接口
 * @Auther: 笑笑是一个码农
 * @Date: 17:01 2020/12/23
 */
@RestController
public class UserInnerController {

    @Resource
    private UserService userService;

    /**
     * 添加用户接口
     * @param userReqVo
     */
    @PostMapping(value = "/v1-inner/provider/user")
    public void addUser(@RequestBody @Validated UserReqVo userReqVo) throws InterruptedException {
        TimeUnit.MINUTES.sleep(1);
        userService.insert(userReqVo);
    }

    /**
     * 查询用户接口
     * @param id
     * @return
     */
    @GetMapping(value = "/v1-inner/provider/user/{id}")
    public UserResVo getUser(@PathVariable("id") Long id){
        return userService.selectById(id);
    }

    /**
     * 修改用户接口
     * @param id
     * @param userReqVo
     */
    @PutMapping(value = "/v1-inner/provider/user/{id}")
    public void updateUser(@PathVariable("id") Long id, @RequestBody @Validated UserReqVo userReqVo){
        userService.update(id, userReqVo);
    }

    /**
     * 删除用户接口
     * @param id
     */
    @DeleteMapping(value = "/v1-inner/provider/user/{id}")
    public void deleteUser(@PathVariable("id") Long id){
        userService.delete(id);
    }
}

